﻿#region Copyright Notice
// This file is part of GestionPedago.
// <description>
// Copyright (C) 2012 ENI Ecole Informatique
// 
// GestionPedago is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// <program> is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace GestionPedago.ViewModel
{
    /// <summary>
    /// Interaction logic for ListViewDocumentsUC.xaml
    /// </summary>
    public partial class ListViewDocumentsUC : UserControl
    {

        /// <summary>
        /// Constructeur de la liste ListViewDocumentsUC
        /// </summary>
        public ListViewDocumentsUC()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Double clique sur un élément de la liste.
        /// </summary>
        private void ListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ListView ListViewDocs = sender as ListView;
            FileInfo file = ListViewDocs.SelectedItem as FileInfo; 

            ProcessStartInfo execFile = new ProcessStartInfo();
            execFile.FileName = file.FullName;
            System.Diagnostics.Process.Start(execFile);
        }



        /// <summary>
        /// Bouton d'ajout d'un document lié à l'ECF
        /// </summary>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            ObservableCollection<FileInfo> Documents = DataContext as ObservableCollection<FileInfo>;
            OpenFileDialog browse = new OpenFileDialog();
            browse.Multiselect = true;
            if (browse.ShowDialog() ?? false)
            {
                foreach (string file in browse.FileNames)
                    Documents.Add(new FileInfo(file));
            }
        }


        /// <summary>
        /// Bouton de suppression du document sélectionné
        /// </summary>
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            ObservableCollection<FileInfo> Documents = DataContext as ObservableCollection<FileInfo>;
            FileInfo file = ListViewDocuments.SelectedItem as FileInfo;

            if (file != null)
                Documents.Remove(file);
        }


        /// <summary>
        /// Bouton qui ouvre l'explorateur de fichier windows.
        /// </summary>
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Process explorer = new Process();

            explorer.StartInfo.FileName = "explorer.exe";
            explorer.StartInfo.Arguments = @"C:\INSTALL";

            explorer.Start();
        }
    }
}
